﻿window.onunload = release;
window.onresize = resize;
var bbsfox = null;
var popup_paste;
document.addEventListener('DOMContentLoaded', function () {
  var site = getQueryVariable('site');
  var mapcode = getQueryVariable('mapcode');
  if (site) {
    document.getElementById('cmdHandler').setAttribute('mapcode', mapcode);
    bbsfox = new BBSFox();

    //var browserutils = new BBSFoxBrowserUtils();
    //document.title = browserutils.findSiteTitle(document.location.hostname); //try to find site title.
    //bbsfox.isDefaultPref = browserutils.isDefaultPref;
    //bbsfox.prefListener = browserutils.prefListener(function(branch, name) {
    //  bbsfox.onPrefChange(bbsfox, branch, name);
    //});

    bbsfox.setInputAreaFocus();
    resize();
    bbsfox.connect(site);
    createMenuItems(site);
  }
  else {
    alert("empty site!");
  }
});

function release() {
  chrome.contextMenus.remove(popup_paste);
  bbsfox.close();
  bbsfox=null;
}

function resize() {
  if(bbsfox)
    bbsfox.view.fontResize();
}

function createMenuItems(site) {
  if(!chrome.contextMenus)
    return;
}

function msg(str) {
  return chrome.i18n.getMessage(str);
}
